package com.huadao.cart_ccs.experiment.log.environmentLog;

import android.content.Context;
import android.os.Bundle;

import com.huadao.cart_ccs.R;
import com.huadao.cart_ccs.common.TimeUtil;
import com.huadao.cart_ccs.common.adapter.CommonRecycleAdapter;
import com.huadao.cart_ccs.common.adapter.CommonViewHolder;
import com.huadao.cart_ccs.common.adapter.FooterHolder;
import com.huadao.cart_ccs.common.adapter.HeaderHolder;
import com.huadao.cart_ccs.common.adapter.onItemCommonClickListener;
import com.huadao.cart_ccs.experiment.log.baseLoglist.BaseLogListFrag;
import com.huadao.cart_ccs.experiment.log.baseLoglist.BaseLogListPresenter;
import com.huadao.cart_ccs.greendao.entity.EnvironmentParams;

import java.util.List;

public class EnvironmentLogFrag extends BaseLogListFrag {
    public static EnvironmentLogFrag getInstance(int day,String condition){
        Bundle bundle=new Bundle();
        bundle.putInt("day",day);
        bundle.putString("condition",condition);
        EnvironmentLogFrag environmentLogFrag=new EnvironmentLogFrag();
        environmentLogFrag.setArguments(bundle);
        return environmentLogFrag;
    }

    @Override
    protected BaseLogListPresenter createPresenter() {
        return new EnvironmentLogPresenter(this);
    }

    @Override
    protected CommonRecycleAdapter setAdapter() {
        return new EnvironmentAdapter(getActivity(),dataList,R.layout.item_environment,R.layout.head_environment,R.layout.rv_footer);
    }

    class EnvironmentAdapter extends CommonRecycleAdapter<EnvironmentParams>{

        public EnvironmentAdapter(Context context, List<EnvironmentParams> dataList, int layoutId, int headerLayoutId, int footerLayoutId) {
            super(context, dataList, layoutId, headerLayoutId, footerLayoutId);
        }

        private onItemCommonClickListener commonClickListener = new onItemCommonClickListener() {
            @Override
            public void onItemClickListener(int position) {
                if (position == dataList.size()+1) {
                    loadMoreData();
                } else {
                }
            }

            @Override
            public void onItemLongClickListener(int position) {

            }
        };

        @Override
        protected void bindData(CommonViewHolder holder, EnvironmentParams data) {
            holder.setText(R.id.tv_time,TimeUtil.log_sdf.format(data.getDate()));
            holder.setText(R.id.tv_type,data.getTypeStr()+data.getUnit());
            holder.setText(R.id.tv_data,String.format("%.2f",data.getData()));
            holder.setText(R.id.tv_operator,"");
        }

        @Override
        protected void bindFooterData(FooterHolder holder) {
            holder.setCommonClickListener(commonClickListener);
        }

        @Override
        protected void bindHeaderData(HeaderHolder holder) {
            holder.setText(R.id.tv_time,"时间");
            holder.setText(R.id.tv_type,"类型");
            holder.setText(R.id.tv_data,"数值");
            holder.setText(R.id.tv_operator,"操作人");
        }
    }
}
